package login;
class InvalidUsernameException extends Exception {
    //帮助构造父类构造方法
    public InvalidUsernameException(String message) {
        super(message);
    }
}

class InvalidPasswordException extends Exception {
    //帮助构造父类构造方法
    public InvalidPasswordException(String message) {
        super(message);
    }
}
public class Login {
        // 用于存储用户名和密码
        private String userName = "bumoyu";
        private String password = "123456";

        public void login(String username, String password) throws InvalidUsernameException,InvalidPasswordException {
            if (!this.userName.equals(username)) {
                // 如果用户名不正确，抛出异常
                throw new InvalidUsernameException("密码无效!");
            }
            if (!this.password.equals(password)) {
                // 如果密码不正确，抛出异常
                throw new InvalidPasswordException("用户名无效!");
            }
        }

        // 自定义的异常类

        public static void main(String[] args) {
            Login test = new Login();
            try {
                test.login("bumoyu","123456");
                System.out.println("登录成功！");
            } catch (InvalidPasswordException e) {
                e.printStackTrace();
            } catch (InvalidUsernameException e) {
                e.printStackTrace();
            }
        }
}